﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Diagnostics;
using System.Security.Cryptography;
using System.Reflection;

namespace DataApplication
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            if (CheckExist())
            {
                MessageBox.Show("不能重复打开数据中心。");
                Application.Exit();
            }
            else
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
                //处理UI线程异常
                Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
                //处理非UI线程异常
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
                Application.Run(new MainForm());
            }
        }

        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            Log.Write(LogType.Fatal, e.ExceptionObject.ToString());
        }

        static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
        {
            Log.Write(LogType.Fatal, e.Exception.StackTrace);
        }

        private static Boolean CheckExist() //调用方法，传参
        {
            try
            {
                Process[] thisproc = Process.GetProcessesByName("DataApplication");
                return thisproc.Length > 1;
            }
            catch //出现异常，表明 kill 进程失败
            {
                return false;
            }
        }
    }



    public delegate void DataBaseMessageEvent(DaInterFace.MessageType type, String note, Double span);
    public delegate void MobileMessageEvent(DaInterFace.MessageType type, String note, Double span);
    public delegate void PDAMessageEvent(DaInterFace.MessageType type, String note, Double span);
    public delegate void SYNMessageEvent(DaInterFace.MessageType type, String note, Double span);
    public delegate void XModeMessageEvent(DaInterFace.MessageType type, String note, Double span);
}
